#include "test_mask.h"
#include "lines.h"
#include "spiral.h"
#include "pattern.h"
#include "curve_complex.h"


void Test_sbend()
{// draw the testing pattern for the sbends with different radius.

  int N=3;
  double d= 10e-6;
  double o= 0;
  double w= 2e-6;
  double s= 50e-6;
  double r[] = {10e-6, 15e-6, 30e-6, 40e-6, 50e-6, 15e-6};
  
  double space = 20e-6; //space between two adjacent waveguide, it should be > d
  double xzoom = 500e-6; // pattern x span
  
  double dx;
  for (int i=0; i<sizeof(r)/sizeof(r[0]); i++)
  {
    pen_up();
    push_cp();
    dx = sbend_series(d, r[i], o, w, s, N);
    pop_cp();
    pen_down();
    
    dx = xzoom*0.5-dx;
    if (dx>0)
    {
      push_cp();
      sbend_series(d, r[i], o, w, s, N);
      sw(dx, w);
      pop_cp();
      push_cp();
      move(0,0, RAD(180), FLIP);
      sbend_series(d, r[i], o, w, s, N);
      sw(dx, w); 
      pop_cp();
      offset(space);       
    }
    else
    {
      fprintf(stderr, "WARNING: not enough xspan for full layout; skip radius of %e\n", r[i]);
    }
  }  

}

void Test_DC()
{// draw the testing pattern for the directional coupler with different coupling length
  double l[] = {10e-6, 20e-6, 30e-6};
  double w = 2e-6;
  double g = 2e-6;
  double d = 20e-6;
  double r = 50e-6;
  double o = 0e-6;
  
  double xspan = 500e-6;
  double space = 20e-6;
  
  double dx;
  for(int i=0; i<sizeof(l)/sizeof(l[0]); i++)
  {
    push_cp();
    pen_up();
    dx = dc(l[i], w, g, d, r, o);
    pen_down();
    pop_cp();
    
    dx = (xspan -dx)*0.5;
    if (dx>0)
    {
      push_cp();
      sw2(dx, w, d*2+g);
      dc(l[i], w, g, d, r, o);
      sw2(dx, w, d*2+g);
      pop_cp();
      offset(space+2*d+g+w);
    }
    else
    {
      fprintf(stderr, "WARNING: not enough xspan for full layout; skip coupling length of %e\n", l[i]);
    }  
  }
}


/* The MMI design */
int main(void) {
	setfont((char *)"../maskV6_01/caps.plf");
	msk_header("T.Cif", "MMI_layout");
  
  arc_spiral_Archi(30e-6, 4e-6, 0, 6*M_PI, 2e-6); 
    
  arc_spiral_Archi(35e-6, 4e-6, 0, 6*M_PI, 2e-6); 
  //skip(1e-4);
  rotate(M_PI);
  
  arc_spiral_Archi(30e-6, 4e-6, 0, 6*M_PI, 2e-6);
  //ArchiSpiral(9e-3, 30e-6, 2e-6, 2e-6, 0.1e-6);  

  //ArchiSpiralN(90e-3, 300e-6, 2e-6, 2e-6, 0.1e-6, 1);

  
  //Test_sbend();
  //Test_DC();
  
  //sbendN(10e-6, 50e-6, 0, 2e-6, 2e-6, 10);
  //adiabend(10e-6, RAD(90), 1e-6, 2);
  
  //star_coupler(3, 10, 100e-6, 5e-6, 5e-6, 1e-6, 4e-6, 10e-6, true);
  //disc(20e-6);
  //arc_ellipse(40e-6, 20e-6, M_PI/4, -M_PI/3+2*M_PI, 1e-6);
  //pie(30e-6, 0.5*M_PI/2, M_PI/2);
  //skip(40e-6);
  //pie_ellipse(40e-6, 20e-6, -M_PI/4, M_PI/3+2*M_PI);
  
  //arc_ellipse_f(40e-6, 20e-6, -M_PI/4, M_PI/2, 2e-6);
  //arc_ellipse_f(45e-6, 25e-6, -M_PI/4, M_PI/2, 2e-6);
  //arc_ellipse_f(50e-6, 30e-6, -M_PI/4, M_PI/2, 2e-6);
  
  //pie_ellipse(40e-6, 20e-6, M_PI/4, -M_PI);
  //ellipse(40e-6, 20e-6, 2e-6);
  //offset(40e-6);
  //ellipse(40e-6, 20e-6);
  //pie_func(func_ellipse, M_PI/4, -M_PI, 40e-6, 20e-6);
  //skip(50e-6);
  
  //rotate(-RAD(90));
  //taper_sbend(100e-6, 50e-6, 10e-6);
  //skip(50e-6);
  //taper_parabolic(100e-6, 50e-6, 10e-6); 
  // skip(100e-6);
  // cwN(100e-6, M_PI/4, 1e-6, 2e-6, 10);
  // cwN(-100e-6, -M_PI/4, 1e-6, 2e-6, 11);
  
	msk_trailer();
}
